<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head><title>splitDocument</title></head>
	<script language="JavaScript">
	</script>
	<style type="text/css">
	<!--
	body {
		margin-left: 0px;
		margin-top: 0px;
		margin-right: 0px;
		margin-bottom: 0px;
		background-color: #EEF2FB;
	}
	-->
	</style>
	<link href="../images/skin.css" rel="stylesheet" type="text/css" />
    <SCRIPT type="text/javascript">
		var current_page = 0;
		var records = undefined;
		function fileJson(record){
			var fields = record.split(",");
			if(fields.length == 2){
				var _path = fields[0];
				var file = {
					path:fields[0],
					lastModified:fields[1],
					filename:fields[0].substring(_path.lastIndexOf("\\") + 1, _path.length)
				};
				return file;
			}
		}
		function init(){
			var ds = document.getElementById("dataset");
			var _records = ds.getElementsByTagName("span");
			if(null != _records && _records.length > 0){
				current_page = 1;
				records = _records;
				var record_ = fileJson(records[0].firstChild.nodeValue);
				if(typeof(window.iframe_show.show_applet_absoute)=="function"){
					rebuildInput();
					//renderLabel(record_.filename, record_.lastModified);
					window.iframe_show.show_applet_absoute(records[0].childNodes[0].nodeValue);
				}
			}
		}
		function first(){
			current_page = 1;
			window.iframe_show.location.href="frame_temp.jsp";
		}
		function previous(){
			if(current_page == 1){
				alert("No Previous Page!");
			}else{
				current_page = current_page  - 1;
				window.iframe_show.location.href="frame_temp.jsp";
			}
		}
		function next(flag){
			if(current_page == records.length){
				alert("No Next Page!");
			}else{
				current_page = current_page + 1;
				window.iframe_show.location.href="frame_temp.jsp";
			}
		}
		function bottom(){
			current_page = records.length;
			window.iframe_show.location.href="frame_temp.jsp";
		}
		function openpdf(){
			if(typeof(window.iframe_show.show_applet_absoute)=="function"){
				rebuildInput();
				window.iframe_show.show_applet_absoute(records[current_page - 1].childNodes[0].nodeValue);
			}
		}
		function sub(){
			var partitionPath = records[current_page - 1].childNodes[0].nodeValue;
			document.getElementById("partitionPath").value = partitionPath;
		}
		
		function rebuildInput(){
			var partitionPath = records[current_page - 1].childNodes[0].nodeValue
			document.getElementById("partitionPath").value = partitionPath;
			rebuild_f();
		}
		
		function renderLabel(filename, lastModified){
			var label_ = document.getElementById("filename");
			var childs = label_.childNodes;
			for(var i = childs.length - 1; i >= 0; i--) {  
			    label_.removeChild(childs[i]);   
			}
			label_.appendChild(document.createTextNode(filename));			
			var input_ = document.getElementById("d_filename");
			input_.value = filename;			
			var receiveTimes_ = document.getElementById("receiveTimes");
			receiveTimes_.value = lastModified;			
			rebuild_f();
		}
		
		function rebuild_f(){
			var filenames = "";
			var flag = false;
			for(var i = 0; i < records.length; i++){
				var record_ = records[i].firstChild.nodeValue;
				if((i + 1) != current_page){
					if(!flag){
						filenames = filenames + record_;
						flag = true;
					}else{
						filenames = filenames + "#spliter#" +  record_;
					}
				}
			}
			var filenames_ = document.getElementById("filenames");
			filenames_.value = filenames;
		}
	</SCRIPT>
<body onload=init();>
	<div id="dataset" style="display: none">
		<s:iterator value="filenameArray" status="stts">
			<span id="record<s:property value="#stts.index"/>"><s:property value="filenameArray[#stts.index]"/></span>
		</s:iterator>
	</div>
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td>
			 <table width="100%" border="0" cellpadding="0" cellspacing="0">
			 	<tr>
			 		<td width="17" valign="top" background="../images/mail_leftbg.gif"><img src="../images/left-top-right.gif" width="17" height="29" /></td>
				    <td colspan="4" valign="top" background="../images/content-bg.gif"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
				      <tr>
				        <td height="31">Split Documents&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="listFile.action?hospitalFolder=<s:property value="hospitalFolder"/>"/>Back to <s:property value="hospitalFolder"/></a></td>
				      </tr>
				    </table></td>				    				    
				    <td width="16" valign="top" background="../images/mail_rightbg.gif"><img src="../images/nav-right-bg.gif" width="16" height="29" /></td>
			 	</tr>
			 	<tr>						
					<td width="17" background="../images/mail_leftbg.gif"><img src="../images/mail_leftbg.gif" width="17" height="17" /></td>
					<td bgcolor="#F7F8F9" colspan="4"></td>
					<td width="16" background="../images/mail_rightbg.gif"><img src="../images/mail_rightbg.gif" width="16" height="17" /></td>
				</tr>
			 </table>
			</td>			
		</tr>

	<tr><td><table width="100%" border="0" cellpadding="0" cellspacing="0">
			<tr>			<td width="17" background="../images/mail_leftbg.gif"><img src="../images/mail_leftbg.gif" width="17" height="17" /></td>
						<td align="left">FileName: <label id="filename"/></td>
						<td width="16" background="../images/mail_rightbg.gif"><img src="../images/mail_rightbg.gif" width="16" height="17" /></td>
			
				</tr></table></td></tr>
		<tr>
			<td>
				<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#F7F8F9">
					<tr>
						<td width="17" background="../images/mail_leftbg.gif"><img src="../images/mail_leftbg.gif" width="17" height="17" /></td>
						<td align="left"><a href="javascript:first();">First</a>&nbsp;<a href="javascript:previous();">Previous</a>&nbsp;<a href="javascript:next();">Next</a>&nbsp;<a href="javascript:bottom();">Bottom</a></td>
						<td width="16" background="../images/mail_rightbg.gif"><img src="../images/mail_rightbg.gif" width="16" height="17" /></td>
					</tr>
					<tr>
						<td width="17" background="../images/mail_leftbg.gif"><img src="../images/mail_leftbg.gif" width="17" height="17" /></td>
						<td align="left"><iframe border="0" id="iframe_show" src="frame_temp.jsp" width="100%" height="958"></iframe></td>
						<td width="16" background="../images/mail_rightbg.gif"><img src="../images/mail_rightbg.gif" width="16" height="17" /></td>
					</tr>
					<tr>
						<td width="17" background="../images/mail_leftbg.gif"><img src="../images/mail_leftbg.gif" width="17" height="17" /></td>
						<td align="left"><a href="javascript:first();">First</a>&nbsp;<a href="javascript:previous();">Previous</a>&nbsp;<a href="javascript:next();">Next</a>&nbsp;<a href="javascript:bottom();">Bottom</a></td>
						<td width="16" background="../images/mail_rightbg.gif"><img src="../images/mail_rightbg.gif" width="16" height="17" /></td>
					</tr>
					<tr>
						<td width="17" background="../images/mail_leftbg.gif"><img src="../images/mail_leftbg.gif" width="17" height="17" /></td>
						<td align="left">
							<s:form action="partitionFile" id="partitionForm">	
								<s:textfield name="partitionNumber"></s:textfield>
								<s:hidden name="partitionPath" id="partitionPath"></s:hidden>
								<s:hidden name="filenames" id="filenames"></s:hidden>								
								<s:submit />
							</s:form>
						</td>
						<td width="16" background="../images/mail_rightbg.gif"><img src="../images/mail_rightbg.gif" width="16" height="17" /></td>
					</tr>
					<tr>
						<td width="17" background="../images/mail_leftbg.gif"><img src="../images/mail_leftbg.gif" width="17" height="17" /></td>
						<td align="left">
							<table>
								<thead>
									<th>
										Document Name
									</th>
								</thead>	
								<tbody id="document_list">
									
								</tbody>							
							</table>
						</td>
						<td width="16" background="../images/mail_rightbg.gif"><img src="../images/mail_rightbg.gif" width="16" height="17" /></td>
					</tr>
				</table>
			</td>	
		</tr>
		<tr>
			<td>
			 <table width="100%" border="0" cellpadding="0" cellspacing="0">
			 	<tr>
			 		<td width="17" valign="top" background="../images/mail_leftbg.gif"><img src="../images/buttom_left2.gif" width="17" height="17" /></td>
				    <td valign="top" background="../images/buttom_bgs.gif"><img src="../images/buttom_bgs.gif" width="17" height="17"></td>
				    <td width="16" valign="top" background="../images/mail_rightbg.gif"><img src="../images/buttom_right2.gif" width="16" height="17" /></td>
			 	</tr>
			 </table>
			</td>    
		</tr>
	</table>
</body>
</html>
